//
//  CunWuContentViewController.m
//  Cunli
//
//  Created by 湛亚 on 15/10/30.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "CunWuContentViewController.h"
#import "CunWuContent.h"
#import "ContentText.h"
#import "MyDataService.h"
#import "NSString+MD5.h"
#import "UIImageView+WebCache.h"
#import "PeopleDataViewController.h"
#import "YMButton.h"
#import "ReportDetailVC.h"
#import "PointsManager.h"
#import "ConvertToCommonEmoticonsHelper.h"
#import "DXMessageToolBar.h"
#import "TTTAttributedLabel.h"
#import "StudyCommentTableViewCell.h"
#import "MWPhotoBrowser.h"
#import "WFPopThreeView.h"
#import "UIColor+Addition.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@interface CunWuContentViewController ()<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate,DXMessageToolBarDelegate,TTTAttributedLabelDelegate,MWPhotoBrowserDelegate>{
    
    NSMutableArray *commentListArray,*photos;
    UITableView *cunWuContentTableview;
    CunWuContent *cunWuContent;
    NSMutableDictionary *zanDic;
    UILabel *tiShiLabel;
    float imgWidth;
}

@property (strong, nonatomic) DXMessageToolBar *chatToolBar;
@property (nonatomic,strong) WFPopThreeView *operationView;
@property (nonatomic,strong) NSIndexPath *selectedIndexPath;

@end

@implementation CunWuContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"村务公开详情";
    self.view.backgroundColor=[UIColor convertHexColorToUIColor:0xf6f6f6];
    commentListArray=[[NSMutableArray alloc]init];//评论数组
    zanDic=[[NSMutableDictionary alloc]init];//存储已赞的评论id
    imgWidth=(SCREEN_WIDTH-50)/4.0;//图片宽度
    [self createTableView];
    [self createNavButton];
    [self getCunWuContent];//获取村务详情
    [self.view addSubview:self.chatToolBar];//添加评论框
}

-(void)createTableView{
    
    cunWuContentTableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-110) style:UITableViewStyleGrouped];
    cunWuContentTableview.dataSource=self;
    cunWuContentTableview.delegate=self;
    cunWuContentTableview.backgroundColor=[UIColor convertHexColorToUIColor:0xf6f6f6];
    cunWuContentTableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:cunWuContentTableview];
}

- (DXMessageToolBar *)chatToolBar
{
    if (_chatToolBar == nil) {
        
        _chatToolBar = [[DXMessageToolBar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - [DXMessageToolBar defaultHeight], SCREEN_WIDTH, [DXMessageToolBar defaultHeight])];
        _chatToolBar.isComment=YES;
        _chatToolBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;
        _chatToolBar.delegate = self;
    }
    
    return _chatToolBar;
}

-(void)keyBoardHidden
{
    [self.chatToolBar endEditing:YES];
}

-(void)createNavButton{
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 28, 28);
    [leftBtn setImage:[UIImage imageNamed:@"regback01"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    leftBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarItem;
}

-(void)goBack{
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 获取村务公开详情

-(void)getCunWuContent{
    
    NSMutableDictionary *CheckParams =[[NSMutableDictionary alloc]init];
    
    [CheckParams setObject:[Config getOwnUserID] forKey:@"userid"];
    [CheckParams setObject:self.itemid forKey:@"itemid"];
    
    NSString *resultSign = [NSString getSignFromParam:CheckParams andSession:[Config getOwnSession]];
    [CheckParams setObject:resultSign forKey:@"sign"];
    [MyDataService requestURL:@"cwgkdetail.php" httpMethod:@"GET" params:CheckParams fileDatas:nil complection:^(id result) {
        
        NSLog(@"%@",result);
        
        if ([[result objectForKey:@"response"] isEqualToString:@"cwgkdetail"]) {
            
            //cunWuContent=[[CunWuContent alloc]initWithDictionary:[result objectForKey:@"data"]];
            cunWuContent=[CunWuContent yy_modelWithDictionary:[result objectForKey:@"data"]];
            [cunWuContentTableview reloadData];
            [self getCunWuCommentList];
        }else{
            
            MBProgressHUD *hud = [Config createHUD];
            hud.mode = MBProgressHUDModeCustomView;
            hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error"]];
            hud.labelText = @"获取详情失败!";
            [hud hide:YES afterDelay:1];
        }
    }failureAction:^{
        
    }];
    
}

#pragma mark - 获取村务公开评论列表

-(void)getCunWuCommentList{
    
    NSMutableDictionary *CheckParams =[[NSMutableDictionary alloc]init];
    [CheckParams setObject:[Config getOwnUserID] forKey:@"userid"];
    [CheckParams setObject:cunWuContent.item_mid forKey:@"item_mid"];
    [CheckParams setObject:cunWuContent.itemid forKey:@"itemid"];
    [CheckParams setObject:@"1" forKey:@"page"];
    [CheckParams setObject:@"10000" forKey:@"pagesize"];
    NSString *resultSign = [NSString getSignFromParam:CheckParams andSession:[Config getOwnSession]];
    [CheckParams setObject:resultSign forKey:@"sign"];
    
    [MyDataService requestURL:@"commentlist.php" httpMethod:@"GET" params:CheckParams fileDatas:nil complection:^(id result) {
        
        NSLog(@"========%@",result);
        
        if ([[result objectForKey:@"response"] isEqualToString:@"commentlist"]) {
            NSArray *commentlistArray=[result objectForKey:@"commentlist"];
            
            //            if (commentlistArray.count==0) {
            //                return ;
            //            }
            [commentListArray removeAllObjects];
            for (NSDictionary *dic in commentlistArray) {
                //ContentText *content=[[ContentText alloc]initWithDictionary:dic];
                ContentText *content=[ContentText yy_modelWithDictionary:dic];
                [commentListArray addObject:content];
            }
            [cunWuContentTableview reloadData];
        }else{
            
            MBProgressHUD *hud = [Config createHUD];
            hud.mode = MBProgressHUDModeCustomView;
            hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error"]];
            hud.labelText = @"获取评论失败!";
            [hud hide:YES afterDelay:1];
        }
        
    }failureAction:^{
        
    }];
    
}

#pragma mark -UITableView代理

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section==0) {
        return 7;
    }else{
        if (commentListArray.count==0) {
            return 1;
        }else{
            return commentListArray.count;
        }
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdentifier=@"cell";
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    if(!cell){
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.backgroundColor=[UIColor convertHexColorToUIColor:0xf6f6f6];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.section==0) {
        
        switch (indexPath.row){
                
            case 0:{
                
                UILabel *titleLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH-20, 50)];
                titleLab.textAlignment=NSTextAlignmentCenter;
                titleLab.numberOfLines=0;
                titleLab.font=[UIFont systemFontOfSize:20];
                titleLab.text=cunWuContent.title;
                [cell addSubview:titleLab];
                return cell;
            }
                break;
                
            case 1:{
                UILabel *objectLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH-20, 20)];
                objectLab.text=cunWuContent.object;
                objectLab.textAlignment=1;
                objectLab.textColor=[UIColor colorWithRed:18/255.0 green:133/255.0 blue:210/255.0 alpha:1];
                [cell addSubview:objectLab];
                return cell;
            }
                break;
                
            case 2:{
                if (cunWuContent.introduce.length>0) {
                    float contentHeight=[self heightWithString:[NSString stringWithFormat:@"    %@",cunWuContent.introduce] andWidth:20];
                    UILabel *contentLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH-20, contentHeight)];
                    contentLab.text=cunWuContent.introduce;
                    contentLab.numberOfLines=0;
                    [cell addSubview:contentLab];
                }
                return cell;
            }
                break;
                
            case 3:{
                
                if (cunWuContent.pics.count>0) {
                    
                    
                    for (int i=0; i<cunWuContent.pics.count; i++) {
                        
                        UIImageView *picImg=[[UIImageView alloc]init];
                        picImg.frame=CGRectMake(10+i%4*(10+imgWidth), 10+i/4*(imgWidth-5), imgWidth, imgWidth-15);
                        picImg.contentMode=UIViewContentModeScaleAspectFill;
                        picImg.clipsToBounds=YES;
                        NSString *urlString=[cunWuContent.pics objectAtIndex:i];
                        [picImg setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"phoneplace.png"]];
                        picImg.tag=i;
                        picImg.userInteractionEnabled=YES;
                        [cell addSubview:picImg];
                        //图片点击事件
                        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkBigPic:)];
                        [picImg addGestureRecognizer:singleTap];
                    }
                }
                return cell;
            }
                break;
                
            case 4:{
                
                UILabel *publishLab=[[UILabel alloc]initWithFrame:CGRectMake(120, 5, SCREEN_WIDTH-130, 20)];
                publishLab.textAlignment=NSTextAlignmentRight;
                publishLab.text=cunWuContent.publish;
                [cell addSubview:publishLab];
                return cell;
            }
                break;
                
            case 5:{
                
                UILabel *addtimeLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH-20, 20)];
                addtimeLab.textAlignment=NSTextAlignmentRight;
                addtimeLab.text=cunWuContent.addtime;
                [cell addSubview:addtimeLab];
                return cell;
            }
                break;
                
            case 6:{
                
                UIView *bgView=[[UIView alloc]initWithFrame:CGRectMake(10, 22, SCREEN_WIDTH-20, 1)];
                bgView.backgroundColor=[UIColor convertHexColorToUIColor:0xdcdddd];
                [cell addSubview:bgView];
                UILabel *titleLab=[[UILabel alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-90)/2.0, 7, 90, 30)];
                titleLab.text=@"热门讨论";
                titleLab.textColor=[UIColor convertHexColorToUIColor:0x333333];
                titleLab.backgroundColor=[UIColor convertHexColorToUIColor:0xf6f6f6];
                titleLab.textAlignment=1;
                [cell addSubview:titleLab];
            }
                break;
            default:
                return cell;
                
        }
    }else{
        
        if (commentListArray.count<1) {
            
            tiShiLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, 150, 20)];
            tiShiLabel.text=@"快来添加讨论吧";
            tiShiLabel.textColor=[UIColor convertHexColorToUIColor:0x333333];
            tiShiLabel.font=[UIFont systemFontOfSize:15];
            [cell addSubview:tiShiLabel];
            return cell;
            
        }else{
            
            [tiShiLabel removeFromSuperview];
            ContentText *content=[commentListArray objectAtIndex:indexPath.row];
            static NSString *cellIdentifier1=@"cell1";
            
            StudyCommentTableViewCell *commentCell =(StudyCommentTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
            if (!commentCell) {
                
                commentCell = [[StudyCommentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier1 andContent:content];
            }
            //头像点击事件
            commentCell.headImg.tag=indexPath.row;
            UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lookPersonInfo:)];
            [commentCell.headImg addGestureRecognizer:singleTap];
            
            commentCell.nameLabel.tag=indexPath.row;
            UITapGestureRecognizer *nameSingleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lookPersonInfo:)];
            [commentCell.nameLabel addGestureRecognizer:nameSingleTap];
            
            //网址链接代理
            //commentCell.commentLabel.delegate=self;
            
            commentCell.moreButton.appendIndexPath=indexPath;
            [commentCell.moreButton addTarget:self action:@selector(showMoreButton:) forControlEvents:UIControlEventTouchUpInside];

            return commentCell;
        }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.operationView dismiss];
    [self keyBoardHidden];
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        switch (indexPath.row) {
            case 0:
                return 60;
            case 1:
            case 4:
            case 5:
                return 30;
            case 2:{
                if (cunWuContent.introduce.length>0) {
                    return [self heightWithString:[NSString stringWithFormat:@"    %@",cunWuContent.introduce] andWidth:20];
                }else{
                    return 0;
                }
            }
            case 3:{
                NSInteger count=(cunWuContent.pics.count+3)/4;
                return count*imgWidth;
            }
            default:
                return 44;
        }
    }else{
        
        if (commentListArray.count<1) {
            return 30;
        }else{
            
            ContentText *content=[commentListArray objectAtIndex:indexPath.row];
            float height=[self heightWithString:content.content andWidth:80];
            return height+60;
        }
    }
    
}

#pragma mark -  举报

-(void)juBaoContent:(UIButton *)btn{
    
    [self.view endEditing:YES];
    ContentText *content=[commentListArray objectAtIndex:btn.tag];
    ReportDetailVC *reportVC = [[ReportDetailVC alloc] init];
    reportVC.itemid = [NSString stringWithFormat:@"%d",content.itemid];
    reportVC.m_itemid =@"10";
    [self.navigationController pushViewController:reportVC animated:YES];
}

#pragma mark - 点击头像查看个人信息

-(void)lookPersonInfo:(UIGestureRecognizer *)gestureRecognizer{
    
    ContentText *content=[commentListArray objectAtIndex:gestureRecognizer.view.tag];
    PeopleDataViewController *dataVC=[[PeopleDataViewController alloc]init];
    dataVC.touserid=[NSString stringWithFormat:@"%d",content.userid];
    dataVC.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:dataVC animated:YES];
}

#pragma mark -点赞事件

-(void)zanContent{
    
    ContentText *content=[commentListArray objectAtIndex:_selectedIndexPath.row];
    
    if ([zanDic objectForKey:[NSString stringWithFormat:@"%d",content.itemid]]) {
        
        MBProgressHUD *hud = [Config createHUD];
        hud.mode = MBProgressHUDModeCustomView;
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
        hud.labelText = @"您已点过赞";
        [hud hide:YES afterDelay:1];
        
    }else{
        
        NSMutableDictionary *CheckParams =[[NSMutableDictionary alloc]init];
        [CheckParams setObject:[Config getOwnUserID] forKey:@"userid"];
        [CheckParams setObject:[NSString stringWithFormat:@"%d",content.itemid] forKey:@"itemid"];
        NSString *resultSign = [NSString getSignFromParam:CheckParams andSession:[Config getOwnSession]];
        [CheckParams setObject:resultSign forKey:@"sign"];
        [MyDataService requestURL:@"commentpraise.php" httpMethod:@"GET" params:CheckParams fileDatas:nil complection:^(id result) {
            
            NSLog(@"%@",result);
            
            if ([[result objectForKey:@"response"] isEqualToString:@"commentprise"]) {
                
                MBProgressHUD *hud = [Config createHUD];
                hud.mode = MBProgressHUDModeCustomView;
                hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
                hud.labelText = @"点赞成功!";
                [hud hide:YES afterDelay:1];
                //存储已赞过的评论
                [zanDic setObject:@"zan" forKey:[NSString stringWithFormat:@"%d",content.itemid]];
                //改变点赞行的赞个数
                content.agree=content.agree+1;
                [commentListArray replaceObjectAtIndex:_selectedIndexPath.row withObject:content];
                //                NSIndexPath *indexPath=[NSIndexPath indexPathForRow:btn.tag inSection:1];
                //                StudyCommentTableViewCell *commentCell =(StudyCommentTableViewCell *)[cunWuContentTableview cellForRowAtIndexPath:indexPath];
                //                commentCell.zanCountLab.text=[NSString stringWithFormat:@"%d",content.agree];
                
            }else{
                
                MBProgressHUD *hud = [Config createHUD];
                hud.mode = MBProgressHUDModeCustomView;
                hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error"]];
                hud.labelText = @"网络错误,点赞失败!";
                [hud hide:YES afterDelay:1];
            }
            
        }failureAction:^{
            
        }];
    }
    
}

-(float)heightWithString:(NSString *)introduce andWidth:(float)width{
    
    CGRect rect = [introduce boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0f]} context:nil];
    CGFloat height = ceilf(rect.size.height);
    return height + 10;
}

#pragma mark -  发布评论

- (void)didSendText:(NSString *)text
{
    if ([text isEqualToString:@""]) {
        
        [self showAlertWithMessage:@"输入内容不能为空"];
        return;
    }else{
        
        NSString *willSendText = [ConvertToCommonEmoticonsHelper convertToCommonEmoticons:text];
        NSLog(@">>>>>>>%@",willSendText);
        [self sendContentWithString:willSendText];
    }
}

-(void)sendContentWithString:(NSString *)comment{
    
    NSMutableDictionary *CheckParams =[[NSMutableDictionary alloc]init];
    [CheckParams setObject:[Config getOwnUserID] forKey:@"userid"];
    [CheckParams setObject:cunWuContent.itemid forKey:@"itemid"];
    [CheckParams setObject:cunWuContent.item_mid forKey:@"item_mid"];
    [CheckParams setObject:comment forKey:@"content"];
    
    NSString *resultSign = [NSString getSignFromParam:CheckParams andSession:[Config getOwnSession]];
    [CheckParams setObject:resultSign forKey:@"sign"];
    [MyDataService requestURL:@"comment.php" httpMethod:@"POST" params:CheckParams fileDatas:nil complection:^(id result) {
        
        NSLog(@"%@",result);
        
        if ([[result objectForKey:@"response"] isEqualToString:@"comment"]) {
            
            MBProgressHUD *hud = [Config createHUD];
            hud.mode = MBProgressHUDModeCustomView;
            hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
            hud.labelText = @"发送成功!";
            [hud hide:YES afterDelay:1];
            [self getCunWuCommentList];
            
        }else{
            
            NSString *str=[[result objectForKey:@"error"] objectForKey:@"text"];
            if (str) {
                [self showAlertWithMessage:str];
            }else{
                [self showAlertWithMessage:@"发送失败!"];
            }
            return ;
        }
        
        [self.chatToolBar endEditing:YES];
        
    }failureAction:^{
        
    }];
    
}

- (void)showAlertWithMessage:(NSString *)message
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

#pragma mark - TTTAttributedLabelDelegate 点击网址的超链接
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
    
    NSLog(@">>>>>>%@",url);
    NSString *urlStr=[url absoluteString];
    NSRange foundObj=[urlStr rangeOfString:@"http://" options:NSCaseInsensitiveSearch];
    if(foundObj.length>0) {
        
        [[UIApplication sharedApplication] openURL:url];
    }else{
        
        urlStr=[NSString stringWithFormat:@"http://%@",urlStr];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
    }
    return;
}

#pragma mark - 点击图片查看大图
-(void)checkBigPic:(UIGestureRecognizer *)gestureRecognizer{
    
    UIImageView *img=(UIImageView *)gestureRecognizer.view;
    photos = [NSMutableArray array];
    
    for (NSString *urlString in cunWuContent.big_pics) {
        
        [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:urlString]]];
    }
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.isScrollerPic=YES;
    [browser setCurrentPhotoIndex:img.tag];
    [self.navigationController pushViewController:browser animated:YES];
}

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return photos.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < photos.count) {
        return [photos objectAtIndex:index];
    }
    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 按钮动画

- (void)showMoreButton:(YMButton *)sender{
    
    CGRect rectInTableView = [cunWuContentTableview rectForRowAtIndexPath:sender.appendIndexPath];
    CGFloat origin_Y = rectInTableView.origin.y + sender.frame.origin.y;
    CGRect targetRect = CGRectMake(CGRectGetMinX(sender.frame), origin_Y, CGRectGetWidth(sender.bounds), CGRectGetHeight(sender.bounds));
    if (self.operationView.shouldShowed) {
        [self.operationView dismiss];
        return;
    }
    
    _selectedIndexPath=sender.appendIndexPath;
    ContentText *content=[commentListArray objectAtIndex:_selectedIndexPath.row];
    [self.operationView showAtView:cunWuContentTableview rect:targetRect isFavour:[NSString stringWithFormat:@"%d",content.agree]];
}

#pragma mark -移除展开的按钮

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    [self.operationView dismiss];
    [self.chatToolBar endEditing:YES];
}

#pragma mark -点击展开的按钮事件

- (WFPopThreeView *)operationView {
    
    if (!_operationView) {
        _operationView = [WFPopThreeView initailzerWFOperationView];
        
        __weak __typeof(self)weakSelf = self;
        
        _operationView.didSelectedOperationCompletion = ^(WFOperationType operationType) {
            switch (operationType) {
                case WFOperationTypeLike:
                    [weakSelf zanContent];
                    break;
                case WFOperationTypeReport:
                    [weakSelf reportComment];
                    break;
                case WFOperationTypeDelect:
                    [weakSelf showAlertWithTag:2002];
                    break;
                default:
                    break;
            }
        };
    }
    return _operationView;
}

#pragma mark -举报评论

- (void)reportComment{
    
    [self.view endEditing:YES];
    ContentText *content=[commentListArray objectAtIndex:_selectedIndexPath.row];
    ReportDetailVC *reportVC = [[ReportDetailVC alloc] init];
    reportVC.itemid = [NSString stringWithFormat:@"%d",content.itemid];
    reportVC.m_itemid =@"10";
    [self.navigationController pushViewController:reportVC animated:YES];
}

#pragma mark -删除评论

-(void)showAlertWithTag:(NSInteger )alertTag{
    
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"确定删除?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert show];
    alert.tag=alertTag;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (buttonIndex==1) {
        
        if (alertView.tag==2002){
            [self delectComment];
        }
    }
}

- (void)delectComment{
    
    ContentText *content=[commentListArray objectAtIndex:_selectedIndexPath.row];
    //NSString *type=[NSString stringWithFormat:@"%d",self.type+2];
    NSString *itemid=[NSString stringWithFormat:@"%d",content.itemid];
    [PointsManager delectCommentWithType:@"3" itemid:itemid completionBlock:^(BOOL isSuccess){
        
        if (isSuccess) {
            
            MBProgressHUD *hud = [Config createHUD];
            hud.mode = MBProgressHUDModeCustomView;
            hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
            hud.labelText = @"删除评论成功!";
            [hud hide:YES afterDelay:1];
            
            [self getCunWuCommentList];
            
        }else{
            
            MBProgressHUD *hud = [Config createHUD];
            hud.mode = MBProgressHUDModeCustomView;
            hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error"]];
            hud.labelText = @"删除失败!";
            [hud hide:YES afterDelay:1];
            return ;
        }
        
    }];
}

@end
